package com.lwm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwm.domain.PurchaseApproval;
import com.lwm.domain.ResponseResult;
import com.lwm.dto.PageParams;
import com.lwm.mapper.PurchaseApprovalMapper;
import com.lwm.service.PurchaseApprovalService;
import com.lwm.utils.Code;
import com.lwm.utils.HintMessage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * 采购申请表(PurchaseApproval)表服务实现类
 *
 * @author lzl
 * @since 2023-10-17 16:22:24
 */
@Service("purchaseApprovalService")
public class PurchaseApprovalServiceImpl implements PurchaseApprovalService {
    @Resource
    private PurchaseApprovalMapper purchaseApprovalMapper;


    @Override
    public ResponseResult<PurchaseApproval> getById(Long id) {
        PurchaseApproval purchaseApproval = purchaseApprovalMapper.getById(id);
        return new ResponseResult<>(Code.GET_OK, HintMessage.GET_OK_HINT, purchaseApproval);
    }

    @Override
    public ResponseResult<PageInfo<PurchaseApproval>> page(PurchaseApproval purchaseApproval, PageParams pageParams) {
        PageInfo<PurchaseApproval> pageInfo = PageHelper.startPage(pageParams.getPage(), pageParams.getSize())
                .doSelectPageInfo(() -> purchaseApprovalMapper.getPage(purchaseApproval));
        return new ResponseResult<>(Code.GET_OK, HintMessage.GET_OK_HINT, pageInfo);
    }

    @Override
    public ResponseResult update(PurchaseApproval purchaseApproval) {
        if (purchaseApproval == null || purchaseApproval.getId() == null) return new ResponseResult(Code.UPDATE_ERR, HintMessage.EDIT_LACK_ID);
        purchaseApprovalMapper.update(purchaseApproval);
        return new ResponseResult(Code.UPDATE_OK, HintMessage.EDIT_OK_HINT);
    }
}
